using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QLNS.Data;
using QLNS.Object;
using System.Windows.Forms;

namespace QLNS.Control
{
    class NhatKyBangLuongCtrl
    {
        NhatKyBangLuongData data = new NhatKyBangLuongData();

        BindingSource bs = new BindingSource();
        public void HienthiNhatKyBangLuongDataGridview(DataGridView dg, BindingNavigator bn)
        {
            BindingSource bs = new BindingSource();
            DataTable tbl = data.DanhSachNhatKyBangLuong();
            bs.DataSource = tbl;
            bn.BindingSource = bs;
            dg.DataSource = bs;

        }

        public void HienthiNhatKyBangLuongDataGridview(System.Windows.Forms.DataGridView dg, System.Windows.Forms.BindingNavigator bn,
            DateTimePicker dtpThang,ComboBox cmbNhanVien, ComboBox cmbPhongBan,ComboBox cmbChucVu,TextBox txtLuong)
        {
            System.Windows.Forms.BindingSource bs = new System.Windows.Forms.BindingSource();
            bs.DataSource = data.DanhSachNhatKyBangLuong();

            dtpThang.DataBindings.Clear();
            dtpThang.DataBindings.Add("Value", bs, "Thang");

            cmbNhanVien.DataBindings.Clear();
            cmbNhanVien.DataBindings.Add("SelectedValue", bs, "ID");            

            cmbPhongBan.DataBindings.Clear();
            cmbPhongBan.DataBindings.Add("SelectedValue", bs, "PhongBan");

            cmbChucVu.DataBindings.Clear();
            cmbChucVu.DataBindings.Add("SelectedValue", bs, "ChucVu");

            txtLuong.DataBindings.Clear();
            txtLuong.DataBindings.Add("Text", bs, "Luong");


            bn.BindingSource = bs;
            dg.DataSource = bs;
        }
        public IList<NhatKyBangLuongInfo> LayDanhSachNhatKyBangLuong()
        {
            DataTable tbl = data.DanhSachNhatKyBangLuong();
            IList<NhatKyBangLuongInfo> ds = new List<NhatKyBangLuongInfo>();

            foreach (DataRow row in tbl.Rows)
            {
                NhatKyBangLuongInfo NKbangluong = new NhatKyBangLuongInfo();
                NKbangluong.Thang = Convert.ToDateTime(row["Thang"]);
                NKbangluong.NhanVien_ID = Convert.ToString(row["NHANVIEN_ID"]);
                NKbangluong.Ten = Convert.ToString(row["Ten"]);
                NKbangluong.PhongBan = Convert.ToString(row["PhongBan"]);
                NKbangluong.ChucVu = Convert.ToString(row["ChucVu"]);
                NKbangluong.Luong = Convert.ToDouble(row["Luong"]);
                ds.Add(NKbangluong);
            }
            return ds;
        }
        public string TimMa(String ma)
        {
            data.TimMa(ma);
            if (data != null)
                return ma;
            return null;
        }

        public string TimTen(string ten)
        {
            data.TimTen(ten);
            if (data != null)
                return ten;
            return null;
        }

        public DataRow NewRow()
        {
            return data.NewRow();
        }
        public void Add(DataRow row)
        {
            data.Add(row);
        }
        public bool Save()
        {
            return data.Save();
        }
        public void Update()
        {
            bs.MoveNext();
            data.Save();
        }
    }
}
